package LeetCode;

public class No108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        if(nums.length==0) return null;
        return buildBST(nums,0,nums.length-1);
    }
    public TreeNode buildBST(int[]nums,int left,int right){
        if (left > right) return null;
        // 选择中间位置（偶数长度时偏左或偏右均可）
        int mid = left + (right - left) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = buildBST(nums, left, mid - 1);
        root.right = buildBST(nums, mid + 1, right);
        return root;
    }
}
